package cn.bdqn.controller;

import cn.bdqn.pojo.DevUser;
import cn.bdqn.service.DevUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/devUserController")
public class DevUserController {
    @Resource
    private DevUserService devUserService;

    //跳转到登录页面
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "dev/login";
    }

    //登录
    @RequestMapping("/login")
    public String doDevLogin(HttpSession session, @Param("devCode") String devCode, @Param("devPassword") String devPassword) {
        DevUser devUser = new DevUser();
        try {
            devUser = devUserService.getDevLogin(devCode, devPassword);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (devUser != null) {
            session.setAttribute("devUser", devUser);
            return "dev/index";
        } else {
            session.setAttribute("error", "用户名或密码不正确");
            return "dev/login";
        }
    }

    //注销
    @RequestMapping("/logout")
    public String logout(HttpSession session) {
        session.invalidate();
        return "index";
    }
}
